package demo13_2;

import java.util.Arrays;

public class Test13_3 {
    public static void main(String[] args) {
        Test13_3 test133 = new Test13_3();
        System.out.println(test133.setstring("abAacdaaab"));
        int[] array1 = new int[]{2,10,13,0,0};
        int[] array2 = new int[]{4,7};
        test133.merge(array1,3,array2,2);
        System.out.println(Arrays.toString(array1));
    }


    public String setstring (String str) {
        int[] array = new int[52];
        //a--97  z--122 26--51
        //A--65  Z--90  0-25
        for(int i = 0;i < str.length();i++) {
            if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {
                array[str.charAt(i) - 71]++;
            }else {
                array[str.charAt(i) - 65]++;
            }
        }

        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {
                if (array[str.charAt(i) - 71] != 0) {
                    stringBuilder.append(str.charAt(i));
                    array[str.charAt(i) - 71] = 0;
                }
            }else {
                if (array[str.charAt(i) - 65] != 0) {
                    stringBuilder.append(str.charAt(i));
                    array[str.charAt(i) - 65] = 0;
                }
            }

        }
        return stringBuilder.toString();
    }
//    A[2,4,6,0,0,0]   B[1,3,5]
    public void merge(int A[], int m, int B[], int n) {

            //[1,3,0,0,0] [0,2,4]  [1,3,0,2,4]
            int a = m;
            for (int i = 0; i < n; i++) {
                A[a] = B[i];
                a++;
            }
            for (int j = 0; j < n + m; j++) {
                for (int i = 0; i < n + m - 1; i++) {
                    if (A[i] > A[i + 1]) {
                        int t = A[i];
                        A[i] = A[i + 1];
                        A[i + 1] = t;
                    }
                }
            }
        }


}
